<%@ page import="cn.imu.entity.User" %>
<%@ page import="cn.imu.entity.UserCount" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Arrays" %>
<%@ page import="java.util.ArrayList" %><%--
  Created by IntelliJ IDEA.
  User: 杨鑫
  Date: 2021/3/26
  Time: 9:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
    <title>登录成功</title>
</head>
<body>
<%!
    String uname;
%>
<%
    User user=(User)request.getAttribute("users");
    Cookie[] cookies= request.getCookies();
    for(Cookie cookie:cookies){
        if(cookie.getName().equals("uname")) {
            uname=cookie.getValue();
            if(uname==null) {
                out.println("session已清除，请重新登录");
                response.sendRedirect("Login.jsp");
            }else{
%>
用户：<%=uname%><br>
<%
            }
        }
    }
%>

恭喜你登录成功！！！！<br>
当前在线人数：${applicationScope.number}<br>
<table border="1" cellspacing="0" width="900px">
    <tr>
        <td>username</td>
        <td>id</td>
        <td>ip</td>
        <td>firstTime</td>

    </tr>
    <c:choose>
        <c:when test="${not empty userList}">
            <c:forEach var="list" items="${applicationScope.userList}">
                <tr>
                    <td>${list.user.name }</td>
                    <td>${list.sessionIdString }</td>
                    <td>${list.ipString }</td>
                    <td>${list.fistTimeString }</td>
                </tr>
            </c:forEach>
        </c:when>
        <c:otherwise>
            <tr>
                <td colspan="3">无在线用户</td>
            </tr>
        </c:otherwise>
    </c:choose>
<%--<%
    List<UserCount> userCountList=(ArrayList<UserCount>)request.getSession().getServletContext().getAttribute("userList");
    if(userCountList!=null){
        for(UserCount userCount:userCountList){
 %>
    <tr>
    <td><%=userCount.getSessionIdString()%></td>
    <td><%=userCount.getIpString() %></td>
    <td><%=userCount.getFistTimeString() %></td>
    </tr>
    <%
        }
    }
%>--%>
</table>
<form action="LoginOutServlet" method="get">
    <input type="submit" value="退出系统">
</form>
</body>
</html>

